<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
  
    <script>
        //数组的代理，
        //让数组的name在网页上显示不超过5个，否则之后加上省略号
        let arr=[
            {name:"js课程学习",
            grade:84

            }
            ,
            {
                name:"css",
                grade:78
            },
            {
                name:"mysql课程学习",
                grade:79
            }
        ];
        let proxy=new Proxy(arr,{
            get(arr,key){
                const len=5;//不超过5
              return arr[key].name.length>5?arr[key].name.substr(0,len)+".".repeat(3)
              :arr[key].name;
            }
        });
      
        console.log( proxy[1]);
       
    </script>
</body>
</html>